package com.ylsk.check.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ylsk.check.domain.dto.RectificationReportDTO;
import com.ylsk.check.domain.so.CheckProblemSO;
import com.ylsk.check.domain.vo.CheckProblemVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ylsk.common.annotation.Log;
import com.ylsk.common.core.controller.BaseController;
import com.ylsk.common.core.domain.AjaxResult;
import com.ylsk.common.enums.BusinessType;
import com.ylsk.check.domain.CheckProblem;
import com.ylsk.check.service.ICheckProblemService;
import com.ylsk.common.utils.poi.ExcelUtil;
import com.ylsk.common.core.page.TableDataInfo;

/**
 * 施工检查问题Controller
 *
 * @author yangsy
 * @date 2023-12-21
 */
@RestController
@RequestMapping("/check/checkProblem")
public class CheckProblemController extends BaseController
{
    @Autowired
    private ICheckProblemService checkProblemService;

    /**
     * 查询施工检查问题列表
     */
    @PreAuthorize("@ss.hasPermi('check:checkProblem:list')")
    @GetMapping("/list")
    public TableDataInfo list(CheckProblemSO checkProblemSO)
    {
        startPage();
        List<CheckProblemVO> list = checkProblemService.selectCheckProblemList(checkProblemSO);
        return getDataTable(list);
    }

    /**
     * 导出施工检查问题列表
     */
    @PreAuthorize("@ss.hasPermi('check:checkProblem:export')")
    @Log(title = "施工检查问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheckProblemSO checkProblemSO)
    {
        List<CheckProblemVO> list = checkProblemService.selectCheckProblemList(checkProblemSO);
        ExcelUtil<CheckProblemVO> util = new ExcelUtil<CheckProblemVO>(CheckProblemVO.class);
        util.exportExcel(response, list, "施工检查问题数据");
    }

    /**
     * 获取施工检查问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('check:checkProblem:query')")
    @GetMapping(value = "/{checkProblemId}")
    public AjaxResult getInfo(@PathVariable("checkProblemId") Long checkProblemId)
    {
        return success(checkProblemService.selectCheckProblemByCheckProblemId(checkProblemId));
    }

    /**
     * 新增施工检查问题
     */
    @PreAuthorize("@ss.hasPermi('check:checkProblem:add')")
    @Log(title = "施工检查问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheckProblem checkProblem)
    {
        return toAjax(checkProblemService.insertCheckProblem(checkProblem));
    }

    /**
     * 修改施工检查问题
     */
    @PreAuthorize("@ss.hasPermi('check:checkProblem:edit')")
    @Log(title = "施工检查问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RectificationReportDTO rectificationReportDTO)
    {
        return toAjax(checkProblemService.saveRectificationReport(rectificationReportDTO));
    }

    /**
     * 删除施工检查问题
     */
    @PreAuthorize("@ss.hasPermi('check:checkProblem:remove')")
    @Log(title = "施工检查问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{checkProblemIds}")
    public AjaxResult remove(@PathVariable Long[] checkProblemIds)
    {
        return toAjax(checkProblemService.deleteCheckProblemByCheckProblemIds(checkProblemIds));
    }


    /**
     * 查询施工检查问题不分页列表
     */
    @GetMapping("/selectList")
    public AjaxResult selectList(CheckProblemSO checkProblemSO)
    {
        List<CheckProblemVO> list = checkProblemService.selectUnReviewCheckProblemList(checkProblemSO);
        return success(list);
    }
}
